<?php

class AutoconfigController extends AppController {

    public $uses = array("Autoconfig");

    public function __construct() {
        parent::__construct();
    }

    public function admin_index() {
        $this->title = "Ustawienia";
    }

    public function admin_portal() {
        $this->title = "Ustawienia portalu";
    }

    public function admin_chatbox() {
        $this->title = "Ustawienia chatboxu";
    }

    public function admin_menu() {
        $this->title = "Menu";
    }

    public function beforeFilter() {
        parent::beforeFilter();
        if (isset($this->data['save']) && $this->data['save'] == 'true') {
            if ($this->authorizedAsAdmin) {
                $configData = array();
                foreach ($this->data as $var => $value) {
                    if (startsWith($var, "autoconfig_")) {
                        $varname = str_replace("_autoconfig_", "", "_" . $var);
                        $configData[$varname] = $value;
                    }
                }
                $this->Autoconfig->save($configData);
            } else {
                $this->trigger404();
            }
        }
    }

}

?>
